package com.android.pagemarket.ui.widget;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout.LayoutParams;
import android.widget.PopupWindow;

import com.android.pagemarket.MyApplication;
import com.android.pagemarket.R;

/*********************************************************
 * @author : zhaohua
 * @version : 2012-11-1
 * @see : 设置更多弹出框
 * @Copyright : copyrights reserved by personal 2007-2011
 **********************************************************/
public class MorePopWindow extends PopupWindow implements OnCheckedChangeListener
{
    Context mContext;
    private CheckBox chk_outtip;
    private CheckBox chk_qouttip;
    private CheckBox chk_promotip;
    private OnClickListener listner;
    
    public MorePopWindow(Context context, OnClickListener listner)
    {
        super(LayoutInflater.from(context)
                .inflate(R.layout.popview_more, null), 
                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        mContext = context;
        this.listner = listner;
        setBackgroundDrawable(new ColorDrawable(0x99000000));
        setTouchable(true);
        setFocusable(true);
        setOutsideTouchable(true);
        
        initViews();
    }
    
    private void initViews()
    {
        View v = getContentView();
        
        v.findViewById(R.id.btn_report).setOnClickListener(listner);
        v.findViewById(R.id.btn_checkversion).setOnClickListener(listner);
        v.findViewById(R.id.btn_about).setOnClickListener(listner);
        chk_outtip = (CheckBox)v.findViewById(R.id.chk_outtip);
        chk_qouttip = (CheckBox)v.findViewById(R.id.chk_qouttip);
        chk_promotip = (CheckBox)v.findViewById(R.id.chk_promotip);
    
        chk_outtip.setOnCheckedChangeListener(this);
        chk_qouttip.setOnCheckedChangeListener(this);
        chk_promotip.setOnCheckedChangeListener(this);
        
        chk_promotip.setChecked(MyApplication.getContext().isPushOn(true,false,false));
        chk_outtip.setChecked(MyApplication.getContext().isPushOn(false,true,false));
        chk_qouttip.setChecked(MyApplication.getContext().isPushOn(false,false,true));
    }
    
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
    {
        switch(buttonView.getId())
        {
            case R.id.chk_outtip:
            {
                MyApplication.getContext().setPushOn(null,isChecked,null);
                break;
            }
            case R.id.chk_qouttip:
            {
                MyApplication.getContext().setPushOn(null,null,isChecked);
                break;
            }
            case R.id.chk_promotip:
            {
                MyApplication.getContext().setPushOn(isChecked, null, null);
                break;
            }
        }
    }
}
